import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store/index";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "login",
    component: () => import("@/components/admin/Login.vue"),
  },
  {
    path: "/admin/admin",
    name: "adminUser",
    component: () => import("@/components/admin/adminUser.vue"),
  },
  {
    path: "/admin/userIndex",
    name: "userIndex",
    component: ()=>import("@/components/admin/userIndex.vue"),
  },
  {
    path: "/admin/user",
    name: "User",
    component: () => import("@/components/admin/user.vue"),
  },
  {
    path: "/admin/mendian",
    name: "adminMendian",
    component: () => import("@/components/admin/mendian.vue"),
  },
  {
    path: "/admin/fenlei",
    name: "adminFenlei",
    component: () => import("@/components/admin/fenlei.vue"),
  },
  {
    path: "/admin/orders",
    name: "orders", 
    component: () => import("@/view/orders_manage.vue"),
  },
  {
    path: "/admin/goods",
    name: "orders",
    component: () => import("@/view/goods_manage.vue"),
  },
  {
    path: "/admin/staticsproject",
    component: () => import("../view/StaticsProject.vue"),
  },
  {
    path: "/admin/PersonalInfo",
    component: () => import("../view/PersonalInfo.vue"),
  },
  {
    path: "/admin/setup",
    component: () => import("../view/SetUp.vue"),
  },
  {
    path: "/admin/business",
    component: () => import("../view/BusinessView.vue")
  }

];

const router = new VueRouter({
  mode: "history",
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.name != "login" && !store.state.isLogin) {
    next({ name: "login" });
  } else {
    next();
  }
});

export default router;
